/*
 * HotelInfoDialog.java
 *
 * Created on August 20, 2007, 9:06 PM
 */

package org.oslo.ui;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import org.oslo.domain.HotelInfo;


/**
 *
 * @author  nl24167
 */
public class HotelInfoDialog extends javax.swing.JDialog {
    
    private final static float STAR_LOW = 0;
    private final static float STAR_HIGH = 5;
    
    /** Creates new form HotelInfoDialog */
    public HotelInfoDialog(java.awt.Frame parent, boolean modal, HotelInfo info) {

        super(parent, modal);
        initComponents();
            
        try {
            BufferedImage image = javax.imageio.ImageIO.read(new java.io.File("resources/images/trans-stars-small.png"));

            Graphics2D graphics = (java.awt.Graphics2D) image.getGraphics();
            AlphaComposite myAlpha = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_IN, 0.3F);
            graphics.setComposite(myAlpha);
            graphics.setColor(java.awt.Color.RED);
            
            int height = image.getHeight();
            int width = image.getWidth();
            
            int starSize = Math.round(new Float((width/100f) * (info.getNumberOfStars()/STAR_HIGH)*100));
            float size = new Float((width/100f) * (info.getNumberOfStars()/STAR_HIGH)*100);
            graphics.fillRect(0, 0, starSize, height);
            jLabel1.setIcon(new ImageIcon(image));
            
            addressField.setText(info.getAddress());
            nameField.setText(info.getName());
            cityField.setText(info.getCity());
            lowPriceField.setText(Float.toString(info.getPriceLow()));
            priceFieldHigh.setText(Float.toString(info.getPriceHigh()));
        } catch (IOException ex) {
            Logger.getLogger("global").log(Level.SEVERE, null, ex);
        }
        
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        nameField = new javax.swing.JTextField();
        addressLabel = new javax.swing.JLabel();
        addressField = new javax.swing.JTextField();
        cityLabel = new javax.swing.JLabel();
        cityField = new javax.swing.JTextField();
        priceLabel = new javax.swing.JLabel();
        lowPriceField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        priceFieldHigh = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText(application.Application.getInstance(org.oslo.ui.OSLOApp.class).getContext().getResourceMap(HotelInfoDialog.class).getString("jLabel1.text")); // NOI18N

        nameLabel.setText(application.Application.getInstance(org.oslo.ui.OSLOApp.class).getContext().getResourceMap(HotelInfoDialog.class).getString("nameLabel.text")); // NOI18N

        addressLabel.setText(application.Application.getInstance(org.oslo.ui.OSLOApp.class).getContext().getResourceMap(HotelInfoDialog.class).getString("addressLabel.text")); // NOI18N

        cityLabel.setText(application.Application.getInstance(org.oslo.ui.OSLOApp.class).getContext().getResourceMap(HotelInfoDialog.class).getString("cityLabel.text")); // NOI18N

        priceLabel.setText(application.Application.getInstance(org.oslo.ui.OSLOApp.class).getContext().getResourceMap(HotelInfoDialog.class).getString("priceLabel.text")); // NOI18N

        jLabel2.setText(application.Application.getInstance(org.oslo.ui.OSLOApp.class).getContext().getResourceMap(HotelInfoDialog.class).getString("jLabel2.text")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nameLabel)
                    .addComponent(addressLabel)
                    .addComponent(cityLabel)
                    .addComponent(priceLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(cityField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                    .addComponent(addressField, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                    .addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lowPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(priceFieldHigh, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameLabel)
                    .addComponent(nameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addressLabel)
                    .addComponent(addressField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cityLabel)
                    .addComponent(cityField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(priceLabel)
                    .addComponent(lowPriceField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(priceFieldHigh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addContainerGap(59, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                HotelInfo info = new HotelInfo();
                info.setNumberOfStars(3.5f);
                HotelInfoDialog dialog = new HotelInfoDialog(new javax.swing.JFrame(), true,info);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField addressField;
    private javax.swing.JLabel addressLabel;
    private javax.swing.JTextField cityField;
    private javax.swing.JLabel cityLabel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextField lowPriceField;
    private javax.swing.JTextField nameField;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField priceFieldHigh;
    private javax.swing.JLabel priceLabel;
    // End of variables declaration//GEN-END:variables
    
}
